package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsSightseeingBusParam;
import com.macro.mall.model.BmsSightseeingBus;
import com.macro.mall.service.BmsSightseeingBusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 观光车Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsSightseeingBusController")
@Tag(name = "BmsSightseeingBusController", description = "观光车管理")
@RequestMapping("/sightseeingBus")
public class BmsSightseeingBusController {
    @Autowired
    private BmsSightseeingBusService bmsSightseeingBusService;

    @ApiOperation("添加观光车")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsSightseeingBusParam bmsSightseeingBusParam) {
        int count = bmsSightseeingBusService.create(bmsSightseeingBusParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改观光车")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsSightseeingBusParam bmsSightseeingBusParam) {
        int count = bmsSightseeingBusService.update(bmsSightseeingBusParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("分页查询观光车")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsSightseeingBus>> getList(@RequestBody BmsSightseeingBusParam bmsSightseeingBusParam) {
        List<BmsSightseeingBus> bmsSightseeingBusList = bmsSightseeingBusService.getList(bmsSightseeingBusParam);
        return CommonResult.success(CommonPage.restPage(bmsSightseeingBusList));
    }

    @ApiOperation("根据id获取观光车信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsSightseeingBus> getItem(@PathVariable Long id) {
        BmsSightseeingBus BmsSightseeingBus = bmsSightseeingBusService.getItem(id);
        return CommonResult.success(BmsSightseeingBus);
    }

    @ApiOperation("删除观光车")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestBody List<Long> ids) {
        int count = bmsSightseeingBusService.delete(ids);
        return CommonResult.success(count);
    }


    @ApiOperation("修改观光车状态")
    @RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> updateShowStatus(@RequestBody BmsSightseeingBusParam bmsSightseeingBusParam) {
        int count = bmsSightseeingBusService.updateShowStatus(bmsSightseeingBusParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }



    @ApiOperation("小程序查询观光车")
    @RequestMapping(value = "/mpList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<BmsSightseeingBus>> getMpList() {
        List<BmsSightseeingBus> bmsSightseeingBusList = bmsSightseeingBusService.getMpList();
        return CommonResult.success(bmsSightseeingBusList);
    }


    /**
     * 小程序观光车详情
     */

    @ApiOperation("小程序观光车详情")
    @RequestMapping(value = "/mpDetail/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<BmsSightseeingBus>> getMpDetail(@PathVariable Long id) {
        List<BmsSightseeingBus> bmsSightseeingBus = bmsSightseeingBusService.getMpDetail(id);
        return CommonResult.success(bmsSightseeingBus);
    }
}
